1 using ExitGames.Client.Photon;
2 using
UnityEngine;
3 using
System.Collections;
4 using
Hashtable = ExitGames.Client.Photon.Hashtable;
5
6 public
class IELdemo : MonoBehaviour
7 {
8     
public Transform[] cubes;
9
10     
#region CONNECTION HANDLING
11
12     
public void Awake()
13     {
14         
if (!PhotonNetwork.connected)
15         {
16             PhotonNetwork.autoJoinLobby =
false;
17             PhotonNetwork.ConnectUsingSettings(
"0.9");
18         }
19     }
20
21     
// This is one of the callback/event methods called by PUN (read more in PhotonNetworkingMessage enumeration)
22     
public void OnConnectedToMaster()
23     {
24         PhotonNetwork.JoinRandomRoom();
25     }
26
27     
// This is one of the callback/event methods called by PUN (read more in PhotonNetworkingMessage enumeration)
28     
public void OnPhotonRandomJoinFailed()
29     {
30         PhotonNetwork.CreateRoom(
null, new RoomOptions() {maxPlayers = 4}, null);
31     }
32
33     
// This is one of the callback/event methods called by PUN (read more in PhotonNetworkingMessage enumeration)
34     
public void OnJoinedRoom()
35     {
36     }
37
38     
// This is one of the callback/event methods called by PUN (read more in PhotonNetworkingMessage enumeration)
39     
public void OnCreatedRoom()
40     {
41         Application.LoadLevel(Application.loadedLevel);
42     }
43
44     
#endregion
45
46     
public void Update()
47     {
48         
if (PhotonNetwork.isMasterClient)
49         {
50             
//Only control the cubes if MC
51             
float movement = Input.GetAxis("Horizontal") * Time.deltaTime * 15;
52             
foreach (Transform tran in cubes)
53             {
54                 tran.position +=
new Vector3(movement, 0, 0);
55             }
56         }
57     }
58
59     
public void OnGUI()
60     {
61         GUILayout.Space(
10);
62         
if (PhotonNetwork.isMasterClient)
63         {
64             GUILayout.Label(
"Move the cubes with the left and right keys. Run another client to check movement (smoothing) behaviour.");
65             GUILayout.Label(
"Ping: " + PhotonNetwork.GetPing());
66         }
67         
else if (PhotonNetwork.isNonMasterClientInRoom)
68         {
69             GUILayout.Label(
"Check how smooth the movement is");
70             GUILayout.Label(
"Ping: " + PhotonNetwork.GetPing());
71         }
72         
else
73         {
74             GUILayout.Label(
"Not connected..." + PhotonNetwork.connectionStateDetailed);
75         }
76     }
77 }


This is one of the callbackevent methods called by PUN (read more in PhotonNetworkingMessage enumeration)

This is one of the callbackevent methods called by PUN (read more in PhotonNetworkingMessage enumeration)

This is one of the callbackevent methods called by PUN (read more in PhotonNetworkingMessage enumeration)

This is one of the callbackevent methods called by PUN (read more in PhotonNetworkingMessage enumeration)

Only control the cubes if MC




Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.431 lượt xem

Gõ tìm kiếm nhanh...